package com.zhledu
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Wordcount {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")
    val context: SparkContext = new SparkContext(sparkConf)
    val file: RDD[String] = context.textFile("/Users/zhli/工作空间/IDEA/spark-study/spark-scala/src/main/scala/com/zhledu/Wordcount.scala")
    val words: RDD[String] = file.flatMap(_.split(" "))
    val word: RDD[(String, Int)] = words.map((_, 1))
    val wordCount: RDD[(String, Int)] = word.reduceByKey(_ + _)
    val result: Array[(String, Int)] = wordCount.collect()
    result.foreach(println)
    context.stop()
  }

}
